package GUI;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Font;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;

import Client.BusinessImplements;
import Controler.Search_Result_Controler;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.border.LineBorder;

public class Search_an_Item extends Abstract_Jpanel {
	private JTextField textField;
	private JTextField textField_2;
	public JButton btnApply;
	public ArrayList<String> ans1;
	private JTextField textField_1;
	private JTextField textField_3;
	/**
	 * in this panel you are searching for an Items (books articles...).
	 */
	
	
	
	
	public Search_an_Item() {
		
		JLabel lblBookSearching = new JLabel("Item Searching:");
		lblBookSearching.setBounds(10, 11, 275, 37);
		lblBookSearching.setForeground(new Color(25, 25, 112));
		lblBookSearching.setFont(new Font("MV Boli", Font.BOLD, 30));
		
		JPanel panel = new JPanel();
		panel.setBounds(329, 326, 121, 56);
		 panel.setLayout(null);
		
		 btnApply = new JButton("Apply");
		 btnApply.setFont(new Font("Tahoma", Font.PLAIN, 14));
		 btnApply.setBounds(10, 11, 85, 34);
		 panel.add(btnApply);
		 btnApply.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Search_Result search_result=new Search_Result();
				
						on_screen_unload();
						BusinessImplements.GetInstance().getMainFrame().setContentPane(search_result);	
						search_result.save_answer(ans1);
						search_result.setSize(getMaximumSize());
						search_result.on_screen_load();
				
				
				
				
				
			}
		});
		setLayout(null);
		add(lblBookSearching);
		add(panel);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel_1.setBackground(SystemColor.inactiveCaption);
		panel_1.setBounds(10, 59, 433, 256);
		add(panel_1);
		panel_1.setLayout(null);
		
		JLabel lblItemName = new JLabel("Item name:");
		lblItemName.setBounds(20, 26, 71, 17);
		panel_1.add(lblItemName);
		lblItemName.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		textField = new JTextField();
		textField.setBounds(141, 26, 162, 20);
		panel_1.add(textField);
		textField.setColumns(10);
		
		JLabel lblAuthorName = new JLabel("Author name:");
		lblAuthorName.setBounds(20, 83, 104, 14);
		panel_1.add(lblAuthorName);
		lblAuthorName.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		textField_2 = new JTextField();
		textField_2.setBounds(141, 82, 162, 20);
		panel_1.add(textField_2);
		textField_2.setColumns(10);
		
		JLabel lblItemSubject = new JLabel("Item subject:");
		lblItemSubject.setBounds(20, 138, 104, 14);
		panel_1.add(lblItemSubject);
		lblItemSubject.setFont(new Font("Tahoma", Font.PLAIN, 14));
		

		
		textField_1 = new JTextField();
		textField_1.setBounds(141, 137, 162, 20);
		panel_1.add(textField_1);
		textField_1.setColumns(10);
		
		textField_3 = new JTextField();
		textField_3.setBounds(141, 194, 162, 20);
		panel_1.add(textField_3);
		textField_3.setColumns(10);
		
		JLabel lblItemDescription = new JLabel("Item Description:");
		lblItemDescription.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblItemDescription.setBounds(20, 195, 121, 14);
		panel_1.add(lblItemDescription);

	}
	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void on_screen_load() {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void on_screen_unload() {
		String ItemName, AuthorName, Subject, Description;
		Search_Result_Controler src = new Search_Result_Controler();
		/**
		 * here we will save the thing we want to find
		 */
		ItemName = this.getItemName();
		AuthorName = this.getAuthorName();
		Subject = this.getSubject();
		Description = this.getDescription();
		

/**
 * here we send to server the details for all items 
 */
		
		ans1=src.searchFotItems(ItemName, AuthorName, Subject, Description);
		
	}
	
	public String getItemName ()
	{
		return this.textField.getText();
	}
	
	public String getAuthorName ()
	{
		return this.textField_2.getText();
	}
	
	public String getSubject ()
	{
		return this.textField_1.getText();
	}
	
	public String getDescription ()
	{
		return this.textField_3.getText();
	}
}
